package cn.edu.scau.cmi.ema.base;

import com.google.gson.Gson;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class CmiPagination implements Serializable {


	public static final long serialVersionUID = 1L;
	public static final int INITIAL_PAGE_SIZE = 10; // 默认起始的每页列表显示记录的数目
	protected int paginationSize = INITIAL_PAGE_SIZE; // 初始每页记录条数
	public static final int MAX_PAGE_CURSOR_SIZE = 10; // 默认页面下方链接游标最大显示的数目
	// 当前页，默认表示第一次进入，如果是1
	protected int currentPagination = 1;
	protected int inputPagination = -1; // 在页面导航的页面输入框中输入查看页面，默认没有输入，使用-1代表
	//	protected int clickPagination = -1; // 在页面导航中鼠标点击查看的当前页面，
	protected String nextPagination;//下一页是否选中
	protected String previousPagination;//上一页是否选中
	protected String firstPagination;
	protected String lastPagination;


	protected int totalPaginations; // 总页数目



	protected int totalRecords; // 所有记录数目

	protected int searchBeginCursor; // 分页起始记录的游标beginPageCursor
	protected int searchEndCursor; // 分页终止记录的游标


	//	基本属性以及查找基本属性的取值的Map，基本属性的名称和分页查找的值的Map
	protected Map<String, String> basicPropertyCriteriaMap = new HashMap<String, String>();

	//	属性与类型的Map，jsp页面可以使用这个展示text、option、checkbox等
	protected Map propertyTypeMap = new HashMap();

//	private Map basicPropertyEnglishCriteriaMap


	//外键属性分页，后期的功能还没有完成。
	protected Map<String, CmiPagination> referencePropertyPaginationMap = new HashMap<String, CmiPagination>();
	//	被外键属性分页，后期的功能还没有完成。
	protected Map<String, CmiPagination> referencedPropertyPaginationMap = new HashMap<String, CmiPagination>();

	public Map<String, CmiPagination> getReferencedPropertyPaginationMap() {
		return referencedPropertyPaginationMap;
	}

	public void setReferencedPropertyPaginationMap(Map<String, CmiPagination> referencedPropertyPaginationMap) {
		this.referencedPropertyPaginationMap = referencedPropertyPaginationMap;
	}

	public int getInputPagination() {
		return inputPagination;
	}

	public void setInputPagination(int inputPagination) {
		this.inputPagination = inputPagination;
	}

	public Map<String, String> getBasicPropertyCriteriaMap() {
		return basicPropertyCriteriaMap;
	}

	public void setBasicPropertyCriteriaMap(Map<String, String> compositeConditionMap) {
		this.basicPropertyCriteriaMap = compositeConditionMap;
	}

	//	不需要使用属性
	public Map<String, CmiPagination> getReferencePropertyPaginationMap() {
		return referencePropertyPaginationMap;
	}

	public void setReferencePropertyPaginationMap(Map<String, CmiPagination> attributePaginationMap) {
		this.referencePropertyPaginationMap = attributePaginationMap;
	}


	public CmiPagination() {
		this(10, 1, 1, 1, 0);
	}

	public CmiPagination(int paginationSize, int beginPagination, int currentPagination, int totalPaginations, int totalRecords) {
		this.paginationSize = paginationSize;
//        this.beginPagination = beginPagination;
		this.currentPagination = currentPagination;
		this.totalPaginations = totalPaginations;
		this.totalRecords = totalRecords;
//        this.attributeMap = new HashMap<String, CmiAttributePagination>();
//        initAttribute();
	}

	/* 用于JSP页面分页的方法，
	 * 分页类的重新设置页面属性，每次查询，page对象的一些属性都需要重置。
	 * 页面前端如果因为条件变化，导致分页的总数量发生了变化，这个对象的一些属性就应该重写设置
	 * 该方法应该是在paginationService类中
	 * */



	public int getCurrentPagination() {
		return currentPagination;
	}
	public void setCurrentPagination(int currentPagination) {
		this.currentPagination = currentPagination;
	}
	public int getTotalElements() {
		return totalRecords;
	}
	public void setTotalElements(int totalElements) {
		this.totalRecords = totalElements;
	}
	public int getSearchBeginCursor() {
		return searchBeginCursor;
	}
	public void setSearchBeginCursor(int searchBeginCursor) {
		this.searchBeginCursor = searchBeginCursor;
	}
	public int getSearchEndCursor() {
		return searchEndCursor;
	}
	public void setSearchEndCursor(int searchEndCursor) {
		this.searchEndCursor = searchEndCursor;
	}
	public int getPaginationSize() {
		return paginationSize;
	}
	public void setPaginationSize(int paginationSize) {
		this.paginationSize = paginationSize;
	}
	public int getTotalRecords() {
		return totalRecords;
	}
	public void setTotalRecords(int totalRecords) {
		this.totalRecords = totalRecords;
	}
	public Map getPropertyTypeMap() {
		return propertyTypeMap;
	}

	public void setPropertyTypeMap(Map propertyTypeMap) {
		this.propertyTypeMap = propertyTypeMap;
	}


	//	用于
	@Override
	public String toString() {
		return "CmiRestPagination [paginationSize=" + paginationSize + ", currentPagination=" + currentPagination
				+ ", totalPaginations=" + totalPaginations + ", totalRecords=" + totalRecords + ", searchBeginCursor="
				+ searchBeginCursor + ", searchEndCursor=" + searchEndCursor + /* ", hiddenCurrentPagination="
				+", hiddenTotalPagination=" +  */", inputPagination=" + inputPagination
//				+ ", queryBoxNumber=" + ", selectedCompositeConditions=" + ", inputCompositeConditions="
				+  "]";
	}

	public String toRestString() {
		return "{\"paginationSize\":" + paginationSize + /*", \"beginPagination\":" +  */", \"currentPagination\":"
				+ currentPagination + ", \"totalPaginations\":" + totalPaginations + ", \"totalRecords\":" + totalRecords + ", \"propertyTypeMap\":"
				+ new Gson().toJson(referencePropertyPaginationMap) + "}";
	}

	public String getNextPagination() {
		return nextPagination;
	}

	public void setNextPagination(String nextPagination) {
		this.nextPagination = nextPagination;
	}

	public String getPreviousPagination() {
		return previousPagination;
	}

	public void setPreviousPagination(String previousPagination) {
		this.previousPagination = previousPagination;
	}

	public String getFirstPagination() {
		return firstPagination;
	}

	public void setFirstPagination(String firstPagination) {
		this.firstPagination = firstPagination;
	}

	public String getLastPagination() {
		return lastPagination;
	}

	public void setLastPagination(String lastPagination) {
		this.lastPagination = lastPagination;
	}
	public int getTotalPaginations() {
		return totalPaginations;
	}

	public void setTotalPaginations(int totalPaginations) {
		this.totalPaginations = totalPaginations;
	}

}
